package com.cpfmat.entity.provider;

import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.jdbc.SQL;

import com.cpfmat.entity.Article;

public class ArticleProvider {
	public String update(final Article article) {
		return new SQL(){
			{
				UPDATE("ARTICLE");
				
				if (StringUtils.isNotBlank(article.getColumnId())) {
					SET("COLUMN_ID = #{columnId}");
				}
				
				if (StringUtils.isNotBlank(article.getContent())) {
					SET("CONTENT = #{content}");
				}
				
				if (StringUtils.isNotBlank(article.getImagePath())) {
					SET("IMAGE_PATH = #{imagePath}");
				}
				
				if (article.getViewCounts() >= 0) {
					SET("VIEW_COUNTS = #{viewCounts}");
				}
				
				if(StringUtils.isNotBlank(article.getIndustry())) {
					SET("INDUSTRY = #{industry}");
				}
				
				if(StringUtils.isNotBlank(article.getSubIndustry())) {
					SET("SUB_INDUSTRY = #{subIndustry}");
				}
				
				if(StringUtils.isNotBlank(article.getTitle())) {
					SET("TITLE = #{title}");
				}
				
				if(StringUtils.isNotBlank(article.getSubTitle())) {
					SET("SUB_TITLE = #{subTitle}");
				}
				
				if (article.getDelFlag() != null) {
					SET("DEL_FLAG = #{delFlag}");
				}
				
				if (StringUtils.isNotBlank(article.getInsertUser())) {
					SET("INSERT_USER = #{insertUser}");
				}
				
				SET("UPDATE_TIME = SYSDATE()");
				SET("UPDATE_COUNTS = UPDATE_COUNTS + 1");
				
				WHERE("SEQ_ID = #{seqId}");
			}
		}.toString();
	}

}
